BigDFT.Atoms module

This module defines the atom class, which is a class which contains very general descriptions of a single atom.

AU_to_A = 0.52917721092

Conversion between Atomic Units and Bohr

class Atom(*args, **kwargs)[source]

Bases: collections.abc.MutableMapping

Defines a wrapper for atoms.

An atom may have many quantities associated with it. These quantities are get and set in a dictionary like fashion, allowing an atom to dynamically hold whatever data you need. However, we still wrap it in a class so that we can have some common operations for it, as well as so we can maintain suitable units.

It is this class’s responsibility to extract the main properties of an atom (position, symbol) from the dictionary.

Parameters

data (dict) – A dictionary of miscellaneous values to associate with this atom.

property atomic_number

The atomic number of this atom.

property atomic_weight

The atomic number of this atom.

dict()[source]

Convert to a dictionary.

get_external_potential(units='bohr')[source]

Transform the atom into a dictionary ready to be put as external potential.

get_force()[source]

Returns the force on the atom in the desired units.

Returns

An array of position values.

get_position(units='bohr', cell=None)[source]

Returns the position of the atom in the desired units.

Parameters
  • units (str) – the units to return the position in. Default is bohr.

  • cell (list) – the vectors of the unit cell (3x3). If passed, the minimum image convention is enforced.

Returns

An array of position values.

Whether or not this atom is a link atom or not.

property nel

The number of electrons in this atom.

property q0

Provides the charge of the atom.

property q1

Provides the dipole of the atom.

serialize(units='bohr')[source]

Transform the atom in a dictionary that can be employed for the construction of dataframes or pandas series.

Parameters

units (str) – the units for the positions

Returns

the serialized dictionary

Return type

dict

set_force(force)[source]

Given an atom or a dictionary, this sets the force.

Parameters

force (list) – a list of force values.

set_multipole(mp, correct_charge=True)[source]

Given another atom or a dictionary, this sets the multipole related values of this with those values.

Todo

Arrive at a standard that avoids having to do the charge correction here.

Parameters
  • mp (dict) – a dictionary which contains information about multipoles.

  • correct_charge (bool) – currently there is an inconsistency in terms of gross charge, and this corrects it.

set_position(new_pos, units='bohr')[source]

Set the position of the atom.

Parameters
  • new_pos (list) – a list of floats defining the new position.

  • units (str) – the units of the new position being passed. Default is bohr.

property sym
IsAngstroem(units)[source]

Checks if a string or atom has angstroem as its units.

Parameters

units – either a string, or a (BigDFT.Atoms.Atom).

MULTIPOLE_ANALYSIS_KEYS = ['q0', 'q1', 'q2', 'sigma', 'multipole character']

A list of valid keys for describing a multipole.

atomic_number(sym)[source]

Returns the atomic number associated with the given symbol.

Parameters

sym (str) – the atomic symbol of this atom.

Returns

the atomic number

Return type

(int)

atomic_weight(sym)[source]

Returns the weight number associated with the given symbol.

Parameters

sym (str) – the atomic weight of this atom.

Returns

the atomic weight

Return type

(int)

number_to_symbol(number)[source]

Returns the symbol of atoms with a given atomic number.

Parameters

number (int) – the atomic number to lookup.

Returns

the atomic symbol with the given number.

Return type

(str)

BigDFT.Atoms example

Below we show an example of using the atom class.

def _example():
    """Test the atom module"""
    safe_print("Access the full data")
    test_atom = Atom({'r': [1.0, 0.0, 0.0], 'sym': "He", 'units': 'bohr'})
    safe_print(dict(test_atom))
    # Access the derived data
    safe_print(test_atom.sym)
    safe_print(test_atom.get_position())
    safe_print(test_atom.get_position('angstroem'))
    safe_print()

    safe_print("Create a new atom with different units")
    new_atom = Atom({
        'r': [float(x) for x in test_atom.get_position('angstroem')],
        'sym': test_atom.sym, 'units': 'angstroem'})
    safe_print("Are these atoms equal?")
    safe_print(new_atom == test_atom)
    safe_print()

    safe_print("Now other times we get an array that looks more like this")
    test_atom = Atom(He=[1.0, 0.0, 0.0], units='bohr')
    safe_print(dict(test_atom))
    safe_print("But everything else works as expected")
    safe_print(test_atom.sym)
    safe_print(test_atom.get_position())
    safe_print(new_atom == test_atom)
    safe_print()

    safe_print("The atom can be used as a dict for adding new properties.")
    test_atom["frag"] = "ANA"
    for key, value in test_atom.items():
        safe_print(key, value)
    safe_print()
    safe_print("And if we update the dictionary position or symbol,")
    safe_print("everything else reacts with suitable caution.")
    test_atom["He"] = [-1.0, 0.0, 0.0]
    safe_print(dict(test_atom))
    safe_print(test_atom.get_position('angstroem'))

    safe_print("But you can change the symbol if you are working with the")
    safe_print("other representation.")
    safe_print(dict(new_atom))
    new_atom["sym"] = "Na"
    safe_print(new_atom.sym)
    safe_print(dict(new_atom))
    safe_print()

    safe_print("One final check of the atom comparison")
    new_atom["units"] = "bohr"
    new_atom["r"] = [-1.0, 0.0, 0.0]
    safe_print(new_atom.sym, new_atom.get_position())
    safe_print(test_atom.sym, test_atom.get_position())
    safe_print(new_atom == test_atom)
    safe_print()

    safe_print("We can also update the position")
    safe_print(test_atom.get_position())
    safe_print(dict(test_atom))
    test_atom.set_position([1.0, 1.0, 1.0], units="angstroem")
    safe_print(test_atom.get_position(units="angstroem"))
    safe_print(dict(test_atom))
    safe_print()